package com.lzw.mall.common.mapper;

import com.lzw.mall.common.entity.Cart;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lzw.mall.common.vo.CartVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author lizhenwei
 * @since 2023-04-04
 */
public interface CartMapper extends BaseMapper<Cart> {

    @Select("select cart.*,p.price,p.home_img 'productImg',p.name 'productName' from cart inner join product p on cart.product_id = p.id where member_id=#{id}")
    List<CartVO> selectCartList(Integer id);

    @Delete("delete from cart where id=#{cartid}")
    void doDel(Integer cartid);

    @Select("select * from cart where member_id=#{id} and product_id=#{productId}")
    Cart selectMemberAndProductId(@Param("id") Integer id, @Param("productId") Integer productId);

    @Update("update cart set amount=#{i} where id=#{id}")
    void updateByAmount(@Param("id") Integer id, @Param("i") int i);

    @Update("update cart set amount=#{amount} where id=#{cartid}")
    void updataAmount(@Param("cartid") Integer cartid,@Param("amount") Integer amount);

    List<CartVO> selectCartListByIds(@Param("id") Integer id, @Param("ids") String[] ids);
}
